package com.wg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wg.entity.Scores;
import com.wg.mapper.ScoreMapper;
import com.wg.service.ScoreService;
import org.springframework.stereotype.Service;

@Service
public class ScoreServiceImpl extends ServiceImpl<ScoreMapper, Scores> implements ScoreService {
    @Override
    public void addScore(Long assignId) {
        LambdaQueryWrapper<Scores> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Scores::getUserId, assignId);
        Scores score = getOne(wrapper);
        if(score == null) {
            score = new Scores();
            score.setUserId(assignId).setScore(10);
            save(score);
            return;
        }
        score.setScore(score.getScore() + 10);
        updateById(score);
    }
}
